package cn.kgc.controller;

import cn.kgc.pojo.Excelzzw;
import cn.kgc.pojo.PersonnelGl;
import cn.kgc.pojo.PersonnelJ;
import cn.kgc.pojo.Year_zzw;
import cn.kgc.service.YearService_zzw;
import cn.kgc.util.ExcelUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:赵智文
 * @date: 2022/2/22
 * @description:
 */
@Controller
public class Controller_zzw {
    @Resource
    private YearService_zzw year;

    @RequestMapping("/职员数据综合报表")
    public String go() {
        return "职员数据综合报表";
    }

    @RequestMapping("/showinfo")
    @ResponseBody
    public String showinfo(@RequestParam Integer currentpage, @RequestParam Integer pagesize) {
        PageHelper.startPage(currentpage, pagesize);
        Page<Year_zzw> list = year.selyear();
        PageInfo<Year_zzw> selyear = new PageInfo<Year_zzw>(list);

        return JSON.toJSONStringWithDateFormat(selyear, "yyyy");
    }

    @RequestMapping("excelzzw")
    public String excel(HttpServletRequest request, HttpServletResponse response) {
        try {
            List<Excelzzw> listexcel = year.listexcel();
            ExcelUtil.export2Web(response, "职员数据综合表", "职员数据综合表", Excelzzw.class, listexcel);
            return "";
        } catch (Exception e) {
            return null;
        }
    }

    @RequestMapping("loadById")
    @ResponseBody
    public String loadById(@RequestParam String day, @RequestParam Integer currentpage, @RequestParam Integer pagesize) {
        PageHelper.startPage(currentpage, pagesize);
        Map map = new HashMap();
        map.put("day", day);
        Page<PersonnelJ> sss = year.SelById(map);
        PageInfo<PersonnelJ> list = new PageInfo<PersonnelJ>(sss);
        return JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd");

    }

    @RequestMapping("bingtu")
    @ResponseBody
    public String bingtu() {
        List<Year_zzw> list=year.bingtu();
        return JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd");
    }
}
